package org.example.commodity.activity.queue;

import org.example.commodity.activity.service.CommodityActivityService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
public class CommodityActivityQueueHandler {

    private final CommodityActivityService activityService;

    public CommodityActivityQueueHandler(CommodityActivityService activityService) {

        this.activityService = activityService;
    }


    public void handleMessage(CommodityActivityPurchaseParam purchaseParam) {
        try{
            activityService.decreaseActivityStocks(purchaseParam.getActivityType(),purchaseParam);
        }catch (Exception e){
            log.error("商品活动消息队列处理失败:{}", JSONObject.toJSONString(purchaseParam));
        }
    }
}
